package com.example.mybatisplusdemo.web.controller;

import com.example.mybatisplusdemo.model.dto.PriceComparisonDTO;
import com.example.mybatisplusdemo.service.comparison.PriceComparisonService;
import com.example.mybatisplusdemo.common.JsonResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/comparison")
@RequiredArgsConstructor
public class PriceComparisonController {

    private final PriceComparisonService comparisonService;

    /**
            * 获取航班比价信息
     */
    @GetMapping("/prices/{flightId}")
    public JsonResponse<Object> getPriceComparison(
            @PathVariable Long flightId) {
        try {
            List<PriceComparisonDTO> comparisons = comparisonService.comparePrices(flightId);
            return JsonResponse.success(comparisons, "比价信息获取成功");
        } catch (Exception e) {
            return JsonResponse.failure("获取比价信息失败: " + e.getMessage())
                    .setCode(500);
        }
    }
}